package com.example.cinema.bindingdata;

import android.view.View;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.cinema.R;
import com.example.cinema.drawview.CollapseText;
import com.example.cinema.request.RequestSend;

public class Blan2ListItemData {

    //头像
    @BindingAdapter("comurl")
    public static void setimgurl(View view,String url)
    {
        if(url==null)
        {
            return;
        }
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.defaut_img)
                .error(R.mipmap.defaut_img)
                .fallback(R.mipmap.defaut_img);
        Glide.with(view).load(url)
                .apply(options)
                .into((ImageView) view);
    }
    //内容
    @BindingAdapter("contents")
    public static void settexts(View view,String text)
    {
        CollapseText collapseText = (CollapseText) view;
        collapseText.setTextcontext(text);
        collapseText.postInvalidate();
    }


    //点赞
    public void ZanClick(View view,String vid,String uid)
    {
        ImageView img = (ImageView) view;
        img.getDrawable().setLevel(2);
        int z = Integer.valueOf(this.zanb.get());
        this.zanb.set(String.valueOf(z+1));
        new Thread()
        {
            @Override
            public void run() {
                RequestSend send = new RequestSend(view.getContext());
                send.UserMoodZan(vid,uid);
            }
        }.start();
    }

    public ObservableField<String> image = new ObservableField<>();//头像
    public ObservableField<String> usid = new ObservableField<>();//用户ID
    public ObservableField<String> name = new ObservableField<>();//用户账号
    public ObservableField<String> vids = new ObservableField<>();//动态ID
    public ObservableField<String> tid = new ObservableField<>();//回帖ID
    public ObservableField<String> zanb = new ObservableField<>();//获得赞
    public ObservableField<String> cent = new ObservableField<>();//评价内容
}
